package cm.sms.mapper;

import cm.mapper.BaseMapperX;
import cm.query.QueryWrapperX;
import cm.sms.DO.SmsCodeDO;
import cm.sms.dto.SmsSendDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * @author: yxh
 * @Description: 短信发送
 * @Date: Created in 2022/9/20 11:04
 * @Modified By:
 */
@Mapper
public interface SmsCodeMapper extends BaseMapper<SmsCodeDO> {//BaseMapperX<SmsCodeDO> {

    /**
     * 获得手机最后一个验证码
     */

    default SmsCodeDO selectLastCode(SmsSendDTO smsSendDTO){
        QueryWrapperX<SmsCodeDO> queryWrapperX = new QueryWrapperX();
        queryWrapperX
                .eq("mobile",smsSendDTO.getMobile())
                .orderByDesc("id")
                .limitOnlyOne();
        return this.selectOne(queryWrapperX);
    }

    default SmsCodeDO selectLastCodeByQueryWrapper(SmsSendDTO smsSendDTO){
        QueryWrapper<SmsCodeDO> queryWrapper = new QueryWrapper();
        queryWrapper.lambda()
                .eq(SmsCodeDO::getMobile,smsSendDTO.getMobile())
                .orderByDesc(SmsCodeDO::getId)
                .last("limit 1");
        return this.selectOne(queryWrapper);

    }

}
